<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="ajax.jsp"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!doctype html>
<html lang="zh_CN">
<head>
    <base href="<%=basePath%>"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="/static/js/ajax.js"></script>
    <title>欢迎使用后台管理系统</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f9f9f9;
            color: #333;
            margin: 0;
            padding: 0;
        }

        .form-container {
            margin: 50px auto;
            max-width: 600px;
            padding: 20px;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        .form-title {
            font-size: 24px;
            font-weight: bold;
            margin-bottom: 20px;
            text-align: center;
        }

        .form-item {
            margin-bottom: 15px;
        }

        .form-label {
            display: block;
            font-weight: bold;
            margin-bottom: 5px;
        }

        .form-input {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }

        .form-submit {
            text-align: center;
        }

        .form-submit button {
            padding: 10px 20px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        .form-submit button:hover {
            background-color: #0056b3;
        }

        .form-reset button {
            margin-left: 10px;
            padding: 10px 20px;
            background-color: #f0f0f0;
            color: #333;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        .form-reset button:hover {
            background-color: #e0e0e0;
        }
    </style>
</head>
<body>
<div class="form-container">
    <div id="msg" style="color: red; font-weight: 550; font-size: 16px"></div>
    <div class="form-title">修改管理员信息</div>
    <form id="addForm" name="myform">
        <div class="form-item">
            <label class="form-label">用户名</label>
            <input type="text" name="username" class="form-input" id="username" value="${sessionScope.admin.username}"/>
        </div>
        <div class="form-item">
            <label class="form-label">姓名</label>
            <input type="text" name="realName" class="form-input" id="realName" value="${sessionScope.admin.realName}"/>
        </div>
        <div class="form-item">
            <label class="form-label">联系方式</label>
            <input type="text" name="contact" class="form-input" id="contact" value="${sessionScope.admin.contact}"/>
        </div>
        <div class="form-item">
            <input type="hidden" name="adminId" id="adminId" value="${sessionScope.admin.adminId}"/>
            <input type="hidden" name="password" id="password" value="${sessionScope.admin.password}"/>
            <input type="hidden" name="createTime" id="createTime" value="${sessionScope.admin.createTime}"/>
            <div class="form-submit">
                <button type="button" id="sub">立即提交</button>
                <button type="reset" id="res" class="form-reset">取消重置</button>
            </div>
        </div>
    </form>
</div>
</body>
<script>
    $('#sub').on('click', function (){
        let admin = {
            adminId: document.getElementById('adminId').value,
            username: document.getElementById('username').value,
            realName: document.getElementById('realName').value,
            contact: document.getElementById('contact').value
        }
        axiosInstance.post(
            '/admin/updateAdmin',
            admin,
            {
                headers: headersJson
            }
        ).then((res)=>{
            console.log("res==>", res);
            if (res.data.code == 200){
                console.log("修改成功");
                alert("修改成功");
            }else {
                console.log("修改失败");
                alert("修改出现异常");
            }
        }).catch((e)=>{
            console.log(e);
            console.log("修改失败");
            alert("修改出现异常");
        })
    })
</script>

</html>

